package com.seio.edc.common;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 取得webService接口
 * @author 12
 *
 */
public class EMCconfig {
	private static Log log = LogFactory.getLog(EMCconfig.class);
	private static Properties prop = null;
	private static FileInputStream fi = null;
	private static FileOutputStream fos = null;
	static {
		prop = new Properties();  
        try {  
        	fi = new FileInputStream(Constants.EMCpropertiesPath);
            prop.load(fi);  
        } catch(IOException e) {  
            e.printStackTrace();
            log.error("配置文件取得失败！文件路径： "+Constants.EMCpropertiesPath);
        }  
        finally{
        	if(fi != null){
        		try {
					fi.close();
				} catch (IOException e) {
					e.printStackTrace();
					log.error("配置文件关闭失败！");
				}
        	}
//        	if(prop != null){
//        		prop.clear();
//        	}
        }
	}

	public static String getStringValue(String key) {
		return prop.getProperty(key);
	}
	
	public static void setStringValue(String key,String value){
		try{
			fi = new FileInputStream(Constants.TaskpropertiesPath);
	        prop.load(fi);
	        
	        prop.setProperty(key, value);
	        FileOutputStream fos = new FileOutputStream(Constants.TaskpropertiesPath); 
	        prop.store(fos, "");
	        
		}catch(IOException e) {  
            e.printStackTrace();
            log.error("配置文件取得失败！文件路径： "+Constants.TaskpropertiesPath);
        }  
        finally{
        	if(fi != null){
        		try {
					fi.close();
				} catch (IOException e) {
					e.printStackTrace();
					log.error("配置文件关闭失败！");
				}
        	}
        	if(fos != null){
        		try {
        			fos.close();
				} catch (IOException e) {
					e.printStackTrace();
					log.error("配置文件关闭失败！");
				}
        	}
//        	if(prop != null){
//        		prop.clear();
//        	}
        }
		
        
        
	}

}
